﻿package net.wangit.context;

import javax.servlet.ServletConfig;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.wangit.framework.config.GlobalSettings;
import net.wangit.framework.session.AgileSessionUtil;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


public class ContextUtil {

	private static final Log log = LogFactory
			.getLog(net.wangit.context.ContextUtil.class);

	private ContextUtil() {
	}

	public static void createContext(HttpServletRequest request,
			HttpServletResponse response, ServletConfig config) {
		try {
			request.setCharacterEncoding(GlobalSettings.getEncoding());
			String content_type = request.getContentType();
			if (content_type != null
					&& content_type.indexOf("multipart/form-data") != -1) {
				MultiPartRequest multi = new MultiPartRequest();
				request = new MultiPartRequestWrapper(multi, request);
			}
			AgileSessionUtil.initSession(request);
			LocalContextFactory.createLocalContext(request, response, config);
		} catch (Exception e) {
			log.error("create LocalContext error", e);
		}
	}

}
